/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.cotec.model;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cascade;

/**
 *
 * @author magalhaes
 */
@Entity
@Table(name = "posicao")
@NamedQueries({@NamedQuery(name = "Posicao.findAll", query = "SELECT p FROM Posicao p"), 
			   @NamedQuery(name = "Posicao.findById", query = "SELECT p FROM Posicao p WHERE p.id = :id"), 
			   @NamedQuery(name = "Posicao.findByPosicao", query = "SELECT p FROM Posicao p WHERE p.posicao = :posicao"), 
			   @NamedQuery(name = "Posicao.findByFileira", query = "SELECT p FROM Posicao p WHERE p.fileira = :fileira")
			   })
public class Posicao implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Column(name = "posicao")
    private Long posicao;
    @JoinColumn(name = "fileira", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Fileira fileira;
    @OneToOne
    @JoinColumn(name = "equipamento", referencedColumnName = "id", unique=true)
    private Equipamento equipamento;

    public Posicao() {
    	this.setFileira(new Fileira());
    }

    public Posicao(Posicao posicao) {
    	this.setEquipamento(new Equipamento());
    	this.setFileira(posicao.getFileira());
    	this.setId(posicao.getId());
    	this.setPosicao(posicao.getPosicao());
    }
    
    public Posicao(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getPosicao() {
        return posicao;
    }

    public void setPosicao(Long posicao) {
        this.posicao = posicao;
    }

    public Fileira getFileira() {
        return fileira;
    }

    public void setFileira(Fileira fileira) {
        this.fileira = fileira;
    }

    public Equipamento getEquipamento() {
        return equipamento;
    }

    public void setEquipamento(Equipamento equipamento) {
        this.equipamento = equipamento;
    }

    @Override
    public String toString() {
        return "br.com.cotec.model.Posicao[id=" + id + "]";
    }
    
	@Override
	public boolean equals(Object object) {
		if (!(object instanceof Posicao)) {
			return false;
		}
		Posicao other = (Posicao) object;
		String este = ""+this.getId()+this.getPosicao();
		String outro = ""+other.getId()+other.getPosicao();
		return este.equalsIgnoreCase(outro);
	}
	
	@Override
	public int hashCode() {
		String aux = ""+this.id+this.posicao;
		return aux.hashCode();
	}
}
